package com.binc.testspring.controller;

import com.binc.testspring.common.exceptions.BusinessRtException;
import com.binc.testspring.dto.Result;
import com.binc.testspring.dto.annotation.ContractDto;
import com.binc.testspring.service.IExportService;
import com.binc.testspring.vo.IdVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.Objects;

/**
 * @dictconfig  @diccode  两个自定义注解的使用实例
 *
 */
@Slf4j
@RestController
@RequestMapping("/dict")
@Api(tags = "注解   异常")
public class DictConf_DictCode_controller {

    @Autowired
    IExportService exportService;

    @PostMapping("/decode")
    @ApiOperation(value = "自定义注解 翻译字典", notes = "")
    public Result<ContractDto> transFlowlistExport(HttpServletResponse response, @RequestBody IdVo idVo) throws Exception {
        long start = System.currentTimeMillis();
        ContractDto decode = exportService.decode();
        long end = System.currentTimeMillis();
        log.info(String.format("测试自定义注解 DictConf  DictCode  字典转换", end - start));
        return Result.of("success",decode);
    }

    @PostMapping("/businessRtException")
    @ApiOperation(value = "自定义异常", notes = "businessRtException")
    public Result<ContractDto> businessRtException( Integer id) throws Exception {

        if (!Objects.nonNull(id)) {
            throw  BusinessRtException.of("自定义异常");
        }
        return Result.of("ok",ContractDto.builder().status(1).statusName("haha").build());
    }
}
